﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace KP_CommonLibrary.KP_ObjectReferences
{
    #region KP_OUser
    public class KP_OUser
    {
        static string _user_name="Design-ABC";
        static string _user_pre;
        static string _password;
        static string _comment;
        static bool _is_admin;

        #region Properties

        public static string User_Name
        {
            get { return _user_name; }
            set { _user_name = value; }
        }

        public static string User_Pre
        {
            get { return _user_pre; }
            set { _user_pre = value; }
        }

        public static string Password
        {
            get { return _password; }
            set { _password = value; }
        }

        public static string Comment
        {
            get { return _comment; }
            set { _comment = value; }
        }

        public static bool Is_Admin
        {
            get { return _is_admin; }
            set { _is_admin = value; }
        }
        #endregion

        #region Methods
        public static bool Login()
        { return true; }

        public static bool Login(string p_user_name, string p_password)
        {
            bool _return = false;

            try
            {
                string pass_decode = KP_CommonLibrary.KP_Functions.Encryption.EnCrypt(p_password, KP_SYS_VARIABLE.M_KEY_CRYPT, true);

                DataTable dsUser = KP_DataAccess.KP_DataAccess.Get_DataTable("SELECT * FROM tblUserAcc WHERE User_Name = '" + p_user_name + "' AND Password = '" + pass_decode + "'");

                if (dsUser.Rows.Count > 0)
                {
                    _return = true;

                    KP_CommonLibrary.KP_ObjectReferences.KP_OUser.User_Name = p_user_name;
                    KP_CommonLibrary.KP_ObjectReferences.KP_OUser.Password = pass_decode;
                    KP_CommonLibrary.KP_ObjectReferences.KP_OUser.User_Pre = dsUser.Rows[0]["User_Pre"].ToString();
                    KP_CommonLibrary.KP_ObjectReferences.KP_OUser.Comment = dsUser.Rows[0]["Comment"].ToString();
                    KP_CommonLibrary.KP_ObjectReferences.KP_OUser.Is_Admin = Convert.ToBoolean(dsUser.Rows[0]["Is_Admin"]);
                }
                return _return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable Load_MenuGrand(string user_name)
        {
            DataTable dttemp = new DataTable();
            //string sqlselect = "";

            return dttemp;
        }

        #endregion
    }
    #endregion
}
